<?php

namespace app\common\model\level;

use app\common\model\Goods;
use think\Model;


class Config extends Model
{





    // 表名
    protected $name = 'level_config';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'json_array',
        'tags_array',
    ];

    public function getJsonArrayAttr($value, $data)
    {
        $json_array =  $data['json'] ? json_decode($data['json'], true) : '';
        if (is_array($json_array) && $json_array) {
            foreach ($json_array as $key => &$v) {
                $v['goods_name'] = Goods::where('id', $v['id'])->value('title');
            }
        }
        return $json_array;
    }
    public function getTagsArrayAttr($v, $d)
    {
        $tags_array =  $d['tags'] ? explode(',', $d['tags']) : [];
        return $tags_array;
    }
}
